<template>
  <div>
    <van-nav-bar
      title="确认订单"
      left-text="返回"
      left-arrow
      @click-left="onClickLeft"
    />
    <van-address-edit
      :area-list="areaList"
      show-postal
      :addressInfo="addressInfo"
      show-set-default
      show-search-result
      :search-result="searchResult"
      :area-columns-placeholder="['请选择', '请选择', '请选择']"
      @save="onSave"
      @change-detail="onChangeDetail"
    />
  </div>
</template>

<script>
import $axios from "@/api/request";
export default {
  data() {
    return {
      addressInfo: {
        name: "沈",
        tel: "13762623438",
        postalCode: "312312",
      },
      areaList: {
        province_list: {
          110000: "北京市",
          120000: "湖南省",
        },
        city_list: {
          110100: "北京市",
          120100: "长沙市",
        },
        county_list: {
          110101: "东城区",
          110102: "天心区",
        },
      },
      searchResult: [],
    };
  },
  methods: {
    onSave(content) {
      let obj = {
        name: content.name,
        tel: content.tel,
        country: "",
        province: content.province,
        city: content.city,
        county: content.county,
        areaCode: content.areaCode,
        postalCode: content.postalCode,
        addressDetail: content.addressDetail,
        isDefault: content.isDefault,
      };
      $axios.post("http://zl.huruqing.cn:3003/address/add", obj).then((res) => {
      });
       this.$router.push({
        path: "/adress",
        query: { preOrderId: this.$route.query.preOrderId,total: this.$route.query.total },
      });
    },
    onClickLeft() {
       this.$router.push({
        path: "/adress",
        query: { preOrderId: this.$route.query.preOrderId,total:this.$route.query.total},
      });
    },
    onChangeDetail(val) {
      if (val) {
        this.searchResult = [
          {
            name: "黄龙万科中心",
            address: "杭州市西湖区",
          },
        ];
      } else {
        this.searchResult = [];
      }
    },
  },
};
</script>

<style>
</style>